package 力扣.双指针.最长区间;

public class 字符流中第一个只出现一次的字符_ac64 {
//    https://www.acwing.com/problem/content/60/

    /**
     * 做题之前自己先演算一下
     */
    private String s = new String();
    private int left = -1;
    private int[] cnt = new int[256];
    private int i = -1;
    //Insert one char from stringstream
    public void insert(char ch){
        i++;
        s += ch;
        cnt[(int)ch]++;//大于1则说明重复
        while (left < i && cnt[(int)s.charAt(1+left)] > 1) {//直到没有重复为止
            ++left;
        }
    }
    //return the first appearence once char in current stringstream
    public char firstAppearingOnce(){
        if (left >= i) {
            return '#';
        }
        return s.charAt(left+1);
    }
}
